package com.chushouya.order.dao.repository;


import com.general.framework.core.lang.Longs;
import com.general.framework.data.mybatis.BaseRepository;
import com.chushouya.order.dao.entity.OrderLogEntity;
import com.chushouya.order.dao.mapper.OrderLogEntityMapper;
import com.chushouya.order.dto.admin.order.OrderLogQuery;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;

/**
 * 订单日志Repository
 */
@Repository
@Slf4j
public class OrderLogRepository extends BaseRepository<OrderLogEntityMapper, OrderLogEntity, Long> {

    @Resource
    private OrderLogEntityMapper orderLogEntityMapper;


    public List<OrderLogEntity> selectList(OrderLogQuery query) {
        return this.selectByExample(buildExample(query));
    }

    private Example buildExample(OrderLogQuery query) {
        Example example = this.buildExample();
        if (Longs.notNullAndZero(query.getOrderId())) {
            example.and().andEqualTo("orderId", query.getOrderId());
        }
        example.orderBy("orderLogId").desc();
        return example;
    }

}
